﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Windows.Forms;

namespace eComet
{
    public class ModuleManager
    {

    public static object getInstance(String fileName,String classType) 
    {
      /* Load in the assembly. */
      //MessageBox.Show("Entre1");
      Assembly moduleAssembly = Assembly.LoadFrom(fileName);
      /* Get the types of classes that are in this assembly. */
      //MessageBox.Show("Entre2");
        Type[] types = moduleAssembly.GetTypes();

      /* Loop through the types in the assembly until we find
       * a class that implements a Module.
       */
      //string tipos = "";
      //MessageBox.Show("Entre3");
      foreach (Type type in types) 
      {
        //MessageBox.Show("Entre4 " + type.ToString() + " -> " + type.BaseType.ToString() + " -> " +classType);
          if (type.BaseType != null)
          {
              if (type.BaseType.ToString().Equals(classType))
              {
                  /* Create a new instance of the 'Module'. */
                  //MessageBox.Show("Entre5");
                  return Activator.CreateInstance(type);
              }
          }
        //tipos += type.BaseType.ToString()+"\n";
        //MessageBox.Show(tipos);
      }
      //MessageBox.Show("Entre6");
      return null;
    }



    }
}
